﻿
using Grishko.SerilizeTools;
using Grishko.DataTier;
using OutdoorLib.Context;

using OutdoorLib.BaseEntity.Infrastructure;

namespace OutdoorLib.BaseEntity.Face
{
    [TagNameInfo (TagName ="Employeer")]
    public class Employeer : ContactFace  
    {
        private string _Login= string.Empty ;
        
        [SrchItemInfo(TxtPropertyName = "Login")]       
        public string Login { get { return _Login; } set { _Login = value; } }

        private bool _Disabled = false;
        public bool Disabled { get { return _Disabled; } set { _Disabled = value; } }


        private string _DepartmentId = string.Empty;
        public string DepartmentId { get { return _DepartmentId; } set { _DepartmentId = value; } }


        private FilterList _FilterList = new FilterList();
        
        public FilterList FilterList
        {
            get { return _FilterList; }
            set { _FilterList = value; }
        }


        [EntityNonSerialized]
        [SrchItemInfo(TxtPropertyName = "eMail")]
        public string eMail
        {
            get
            {
                return GetContactValue(EnContactType.Email);

            }
            set
            {
                SetContactValue(EnContactType.Email , value);
            }
        }

        [EntityNonSerialized]
        [SrchItemInfo(TxtPropertyName = "Телефон")]
        public string Phone
        {
            get
            {
                return GetContactValue(EnContactType.Phone);

            }
            set
            {
                SetContactValue(EnContactType.Phone, value);
            }
        }

        
        private string GetContactValue(EnContactType  ContactType)
        {
            Contact c = ContactList.GetMainContact(ContactType);
            if (c == null) return string.Empty;
            return c.ContactValue;
        }


        private void SetContactValue(EnContactType  ContactType, string ContactValue)
        {
            this.ContactList.RemoveItems(ContactType);
            this.ContactList.Add(new Contact { MainContact = true, ContactType=ContactType   , ContactValue = ContactValue });
        }

        
        
        public string Comment { get;set;}
                
                
        private EntityList _Permissions = new EntityList();
        /// <summary>
        /// Перечень подразделений, для работы с ресурсами которых допущен сотрудник
        /// </summary>
        public EntityList Permission { get { return _Permissions; } set { _Permissions = value; } }

        public override void Save()
        {
            base.Save();
        }
        public override void SaveWitchChild()
        {
            base.SaveWitchChild();
        }
                
        public override string LoadProcedure
        {
            get
            {
                
                return "EmployeeLoad";
            }
        }

        //public override void Save(string ConnectionString)
        //{
        //    base.Save(ConnectionString);
        //}
        
     
        

    }

    
}
